package com.ego.service.impl;

import com.ego.commons.pojo.BigAd;
import com.ego.commons.utils.JsonUtils;
import com.ego.dubbo.service.TbContentDubboService;
import com.ego.pojo.TbContent;
import com.ego.service.PortalService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Title
 * @Author Lyg
 * @Description:
 */
@Service
@CacheConfig(cacheNames = "com.ego.portal")
public class PortalServiceImpl implements PortalService {
    @DubboReference
    private TbContentDubboService tbContentDubboService;

    @Value("${ego.bigad.categoryId}")
    private long egoBigadCategoryId;
    @Override
    @Cacheable(key ="'bigad'")
    public String showBigAd() {
        List<TbContent> tbContents = tbContentDubboService.selectAllByCategoryid(egoBigadCategoryId);
        List<BigAd> listBigad = new ArrayList<>();

        for (TbContent tbContent : tbContents) {
            BigAd bigAd = new BigAd();
            bigAd.setWidth(670);
            bigAd.setHeight(240);
            bigAd.setSrc(tbContent.getPic());
            bigAd.setSrcB(tbContent.getPic2());
            bigAd.setHref(tbContent.getUrl());
            bigAd.setWidthB(550);
            bigAd.setHeightB(240);
            bigAd.setAlt("");

            //将广告对象添加到集合中
            listBigad.add(bigAd);
        }
        return JsonUtils.objectToJson(listBigad);
    }
}
